home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / SPACER.PAS < prev    next >
Pascal/Delphi Source File  |  1988-07-13  |  6KB  |  168 lines

  1. {--------------------------------------------------------------}
  2. {                           SPACER                             }
  3. {                                                              }
  4. {             Directory lister with file size tally            }
  5. {                                                              }
  6. {                             by Jeff Duntemann                }
  7. {                             Turbo Pascal 5.00                }
  8. {                             Last update 7/2/88               }
  9. {                                                              }
  10. {  This utility functions similarly to DOS DIR in that it      }
  11. {  displays a directory of files in a subdirectory, but unlike }
  12. {  DIR it keeps a running total of the size of the files       }
  13. {  displayed.  It exists mostly to demonstrate the generation  }
  14. {  of a linked list of directory entries through the procedure }
  15. {  GetDirectory.  Ideally, it should be expanded into a        }
  16. {  utility similar to SWEEP.                                   }
  17. {                                                              }
  18. {     From: COMPLETE TURBO PASCAL 5.0  by Jeff Duntemann       }
  19. {    Scott, Foresman & Co., Inc. 1988   ISBN 0-673-38355-5     }
  20. {--------------------------------------------------------------}
  21.  
  22. PROGRAM Spacer;
  23.  
  24. USES DOS;
  25.  
  26. CONST
  27.   SortByName = True;
  28.   SortByDate = False;
  29.  
  30. TYPE
  31.  String80 = String[80];
  32.  String15 = String[15];
  33.  DTAPtr   = ^SearchRec;
  34.  
  35. {$I TIMEREC.DEF}     { Described in Section 20.6 }
  36. {$I DATEREC.DEF}     { Described in Section 20.6 }
  37. {$I DIRREC.DEF}      { Described in Section 20.7 }
  38.  
  39.  
  40. VAR
  41.   Parms      : Byte;
  42.   SpaceTaken : Real;
  43.   RunUp      : DIRPtr;
  44.   RunDown    : DIRPtr;
  45.   Current    : DIRPtr;
  46.   FileSpec   : String80;
  47.   WorkString : String80;
  48.   Sorted     : Boolean;
  49.   SortSpec   : Boolean;
  50.   Ascending  : Boolean;
  51.   I          : Integer;
  52.  
  53.  
  54. {$I DAYOWEEK.SRC}    { Described in Section 20.6 }
  55. {$I CALCDATE.SRC}    { Described in Section 20.6 }
  56. {$I CALCTIME.SRC}    { Described in Section 20.6 }
  57. {$I DTATODIR.SRC}    { Described in Section 20.7 }
  58. {$I GETDIR.SRC}      { Described in Section 21.4 }
  59. {$I DIRSTRIN.SRC}    { Described in Section 20.7 }
  60.  
  61.  
  62.  
  63. BEGIN
  64.   Sorted := False;           { Set default values }
  65.   SortSpec := SortByName;
  66.   Ascending := True;
  67.   Parms := ORD(ParamCount);  { Convert parm count to ordinal value }
  68.   CASE Parms OF
  69.     0 :
  70.     BEGIN
  71.       Writeln('>>SPACER<<  V2.00  By Jeff Duntemann');
  72.       Writeln('            From the book, COMPLETE TURBO PASCAL 5.0');
  73.       Writeln('            Scott, Foresman & Co. 1988');
  74.       Writeln('            ISBN 0-673-38355-5');
  75.       Writeln;
  76.       Writeln('This program displays ALL files matching a given filespec.');
  77.       Writeln('Hidden and system files are not immune.');
  78.       Writeln('Additionally, it will add up the cumulative file sizes of');
  79.       Writeln('the files matching the filespec, so you can tell how much');
  80.       Writeln('space files in a given subdirectory subtend, or how much');
  81.       Writeln('space you have invested in .PAS files, and so on.');
  82.       Writeln;
  83.       Writeln('CALLING SYNTAX:');
  84.       Writeln;
  85.       Writeln('SPACER <filespec> N|D A|D');
  86.       Writeln;
  87.       Writeln('where <filespec> is a legal DOS filespec, including wildcards.');
  88.       Writeln('The second parameter is either N or D:');
  89.       Writeln('N indicates sort by file name;');
  90.       Writeln('D indicates sort by time and date stamp.');
  91.       Writeln('If not given, entries are displayed in physical order.');
  92.       Writeln;
  93.       Writeln('The third parameter is either A or D:');
  94.       Writeln('A indicates ascending order of display;');
  95.       Writeln('D indicates descending order of display.');
  96.       Writeln('If not given, sort is ascending.');
  97.       Writeln;
  98.       Writeln('For example:');
  99.       Writeln;
  100.       Writeln('SPACER *.PAS N');
  101.       Writeln('  will display all files with the .PAS extension,');
  102.       Writeln('  in ascending sorted order by file name.  Or,');
  103.       Writeln;
  104.       Writeln('SPACER *.PAS D D');
  105.       Writeln('  will display all files with the .PAS extension,');
  106.       Writeln('  in descending order by last-modification date.');
  107.       Halt;
  108.     END;
  109.     1 : FileSpec := ParamStr(1);
  110.     2 : BEGIN
  111.           Sorted := True;
  112.           FileSpec := ParamStr(1);
  113.           WorkString := ParamStr(2);
  114.           CASE UpCase(WorkString[1]) OF
  115.             'D' : SortSpec := SortByDate;
  116.             'N' : SortSpec := SortByName;
  117.             ELSE Sorted := False
  118.           END
  119.         END;
  120.     3 : BEGIN
  121.           Sorted := True;
  122.           FileSpec := ParamStr(1);
  123.           WorkString := ParamStr(2);
  124.           CASE UpCase(WorkString[1]) OF
  125.             'D' : SortSpec := SortByDate;
  126.             'N' : SortSpec := SortByName;
  127.             ELSE Sorted := False
  128.           END;
  129.           IF Sorted THEN
  130.             BEGIN
  131.               WorkString := ParamStr(3);
  132.               CASE UpCase(WorkString[1]) OF
  133.                 'A' : Ascending := True;
  134.                 'D' : Ascending := False;
  135.                 ELSE Ascending := True
  136.               END
  137.             END
  138.         END;
  139.    END; { CASE }
  140.    { Now we actually go out and build a linked list of directory entries, }
  141.    { based on the parms we have parsed out of the command line: }
  142.    GetDirectory(FileSpec,Sorted,SortSpec,RunUp,RunDown);
  143.    IF Ascending THEN Current := RunUp
  144.      ELSE Current := RunDown;
  145.    IF Current = Nil THEN Writeln('No files found.')
  146.      ELSE
  147.        BEGIN
  148.          SpaceTaken := 0.0;
  149.          IF Ascending THEN
  150.            WHILE Current <> NIL DO
  151.              BEGIN
  152.                Writeln(DirToString(Current^));
  153.                SpaceTaken := SpaceTaken + Current^.FileSize;
  154.                Current := Current^.Next
  155.              END
  156.          ELSE
  157.            WHILE Current <> NIL DO
  158.              BEGIN
  159.                Writeln(DirToString(Current^));
  160.                SpaceTaken := SpaceTaken + Current^.FileSize;
  161.                Current := Current^.Prior
  162.              END;
  163.          Writeln;
  164.          Writeln
  165.          ('Total space occupied by these files is ',SpaceTaken:9:0,' bytes.');
  166.        END
  167. END.
  168.